package cn.semcorp.zhuhaizj.controller;

import cn.semcorp.zhuhaizj.pojo.dto.DoUpdateTableRowDTO;
import cn.semcorp.zhuhaizj.pojo.dto.InsertForeignDTO;
import cn.semcorp.zhuhaizj.pojo.dto.InsertPictureForeignDTO;
import cn.semcorp.zhuhaizj.pojo.dto.QueryByConditionDTO;
import cn.semcorp.zhuhaizj.restful.JsonResult;
import cn.semcorp.zhuhaizj.services.impl.ForeignServiceImpl;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@Api(tags = "异物")
@RequestMapping("/foreign")
public class ForeignController {
    @Autowired
    private ForeignServiceImpl service;

    /**
     * 外部导入异物文件数据
     * @param list
     * @return
     */
    @PostMapping("/update/list")
    public JsonResult updateList(@RequestBody List<InsertForeignDTO> list){
        Integer rows = service.updateLists(list);
        return JsonResult.ok("金属异物数据导入成功,分"+rows+"批,共导入"+list.size()+"条记录!");
    }

    /**
     * 查询当月所有的异物数据
     * @return
     */
    @GetMapping("/select/now/month/list")
    public JsonResult selectNowMonthList(){
        return JsonResult.ok(service.selectNowMonthList());
    }

    /**
     * 生成当前数据的趋势图
     * @return
     */
    @PostMapping("/do/picture/for/now")
    public JsonResult doPictureForNew(@RequestBody List<InsertPictureForeignDTO> list){
        return JsonResult.ok(service.doPictureForNew(list));
    }

    /**
     * 临时添加修改表格重量
     * @return
     */
    @PostMapping("/do/update/table/row")
    public JsonResult doUpdateTableRow(DoUpdateTableRowDTO dto){
        service.doUpdateTableRow(dto);
        return JsonResult.ok("修改成功!");
    }


    /**
     * 根据查询条件查询异物数据
     * @return
     */
    @GetMapping("/query/by/condition")
    public JsonResult queryByCondition(QueryByConditionDTO dto){
        return JsonResult.ok(service.queryByCondition(dto));
    }
}
